home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / Filezilla Server / FileZilla_Server-0_9_41.exe / source / misc / md5.h < prev    next >
C/C++ Source or Header  |  2011-11-06  |  4KB  |  112 lines

  1. // MD5.CC - source code for the C++/object oriented translation and 
  2. //          modification of MD5.
  3.  
  4. // Translation and modification (c) 1995 by Mordechai T. Abzug 
  5.  
  6. // This translation/ modification is provided "as is," without express or 
  7. // implied warranty of any kind.
  8.  
  9. // The translator/ modifier does not claim (1) that MD5 will do what you think 
  10. // it does; (2) that this translation/ modification is accurate; or (3) that 
  11. // this software is "merchantible."  (Language for this disclaimer partially 
  12. // copied from the disclaimer below).
  13.  
  14. /* based on:
  15.  
  16.    MD5.H - header file for MD5C.C
  17.    MDDRIVER.C - test driver for MD2, MD4 and MD5
  18.  
  19.    Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
  20. rights reserved.
  21.  
  22. License to copy and use this software is granted provided that it
  23. is identified as the "RSA Data Security, Inc. MD5 Message-Digest
  24. Algorithm" in all material mentioning or referencing this software
  25. or this function.
  26.  
  27. License is also granted to make and use derivative works provided
  28. that such works are identified as "derived from the RSA Data
  29. Security, Inc. MD5 Message-Digest Algorithm" in all material
  30. mentioning or referencing the derived work.
  31.  
  32. RSA Data Security, Inc. makes no representations concerning either
  33. the merchantability of this software or the suitability of this
  34. software for any particular purpose. It is provided "as is"
  35. without express or implied warranty of any kind.
  36.  
  37. These notices must be retained in any copies of any part of this
  38. documentation and/or software.
  39.  
  40. */
  41.  
  42. #include <stdio.h>
  43. #include <fstream>
  44. #include <iostream>
  45.  
  46. using namespace std;
  47.  
  48. class MD5 {
  49.  
  50. public:
  51. // methods for controlled operation:
  52.   MD5              ();  // simple initializer
  53.   void  update     (const unsigned char *input, unsigned int input_length);
  54.   void  update     (istream& stream);
  55.   void  update     (FILE *file);
  56.   void  update     (ifstream& stream);
  57.   void  finalize   ();
  58.  
  59. // constructors for special circumstances.  All these constructors finalize
  60. // the MD5 context.
  61.   MD5              (unsigned char *string); // digest string, finalize
  62.   MD5              (istream& stream);       // digest stream, finalize
  63.   MD5              (FILE *file);            // digest file, close, finalize
  64.   MD5              (ifstream& stream);      // digest stream, close, finalize
  65.  
  66. // methods to acquire finalized result
  67.   unsigned char    *raw_digest ();  // digest as a 16-byte binary array
  68.   char *            hex_digest ();  // digest as a 33-byte ascii-hex string
  69.   friend ostream&   operator<< (ostream&, MD5 context);
  70.  
  71.  
  72.  
  73. private:
  74.  
  75. // first, some types:
  76.   typedef unsigned       int uint4; // assumes integer is 4 words long
  77.   typedef unsigned short int uint2; // assumes short integer is 2 words long
  78.   typedef unsigned      char uint1; // assumes char is 1 word long
  79.  
  80. // next, the private data:
  81.   uint4 state[4];
  82.   uint4 count[2];     // number of *bits*, mod 2^64
  83.   uint1 buffer[64];   // input buffer
  84.   uint1 digest[16];
  85.   uint1 finalized;
  86.  
  87. // last, the private methods, mostly static:
  88.   void init             ();               // called by all constructors
  89.   void transform        (uint1 *buffer);  // does the real update work.  Note 
  90.                                           // that length is implied to be 64.
  91.  
  92.   static void encode    (uint1 *dest, uint4 *src, uint4 length);
  93.   static void decode    (uint4 *dest, uint1 *src, uint4 length);
  94.   //static void memcpy    (uint1 *dest, uint1 *src, uint4 length);
  95.   //static void memset    (uint1 *start, uint1 val, uint4 length);
  96.  
  97.   static inline uint4  rotate_left (uint4 x, uint4 n);
  98.   static inline uint4  F           (uint4 x, uint4 y, uint4 z);
  99.   static inline uint4  G           (uint4 x, uint4 y, uint4 z);
  100.   static inline uint4  H           (uint4 x, uint4 y, uint4 z);
  101.   static inline uint4  I           (uint4 x, uint4 y, uint4 z);
  102.   static inline void   FF  (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, 
  103.                 uint4 s, uint4 ac);
  104.   static inline void   GG  (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, 
  105.                 uint4 s, uint4 ac);
  106.   static inline void   HH  (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, 
  107.                 uint4 s, uint4 ac);
  108.   static inline void   II  (uint4& a, uint4 b, uint4 c, uint4 d, uint4 x, 
  109.                 uint4 s, uint4 ac);
  110.  
  111. };
  112.